<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="Public/Admin/Flat/img/favicon.ico">
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    <script src="Public/jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
	    <script type="text/javascript">
	    	$(function(){
	    		//抓取表单提交事件
	    		$('form').submit(function(){
	    			//抓取表单的所有数据
	    			var formData=$(this).serialize();
	    			//发送异步
	    			$.ajax({
	    				type:"post",
	    				url:"<?php echo U('add')?>",
	    				data:formData,
	    				dataType:'json',
	    				success:function(formData){	    					
	    				    var path = '<?php echo U("edit")?>&glid='+formData.glid;
	    					var str='<tr class="addr">';
								str+='<td>'+formData.glid+'</td>';
								$.each(formData.glvalue,function(i,n){
								str+='<td>'+n+'</td>';
								});
							str+='<td>'+formData.glnum+'</td>';
							str+='<td>'+formData.gltotal+'</td><td >';
									str+='<a href="'+path+'"  class="btn btn-sm btn-warning edit">编辑</a>';
									str+='<a href="javascript:;" glid="'+formData.glid+'" class="btn btn-sm btn-danger del">删除</a></td></tr>';
//								document.write(str)
							$('.addr:last').after(str);
	    				}
	    			});
	    			//组织表单提交
	    			return false;
	    		})
	    		//异步删除  添加未来事件
	    		$('.del').live('click',function(){
	    			var glid=$(this).attr('glid');
	    			if(confirm('确认删除么？')){
		    			$.ajax({
		    				type:'post',
		    				url:"<?php echo U('del')?>",
		    				data:{glid:glid},
		    				dataType:'json',
		    				success:function(glid){
		    				}
		    			})
		    			$(this).parents('tr').remove();
		    		}
		    		
	    		})
	    		
	    	})
	    </script>	    
	</head>
	<body>
		<p class="btn btn-primary btn-block" style="text-align: left;"><a href="<?php echo U('Brand/index')?>">首页&gt;</a><a href=""></a></p>
		<table class="table table-hover">
			<tr class="active">
			  <th width="80">ID</th>
			  <?php foreach ($arr as $k=>$v){?>
				  	<?php if($v[0]['natype']==1){?>
                
				  		<th ><?php echo $v[0]['naname']?></th>
				  	
               <?php }?>
			  <?php }?>
			  <th >库存</th>
			  <th>货号</th>
			  <td>操作</td>
			</tr>
			<tr class="addr"></tr>
			<?php foreach ($gldata as $v){?>
			<tr class="addr">
				<td><?php echo $v['glid']?></td>
				<?php foreach ($v['glvalue'] as $a){?>
					<td><?php echo $a?></td>
				<?php }?>
				<td><?php echo $v['glnum']?></td>
		        <td><?php echo $v['gltotal']?></td>
		        <td >
				<a href="<?php echo U('edit',array('glid'=>$v['glid'],'gid'=>$_GET['gid']))?>"  class="btn btn-sm btn-warning edit">编辑</a>
				<a href="javascript:;" glid="<?php echo $v['glid']?>" class="btn btn-sm btn-danger del" >删除</a></td></tr>
			<?php }?>
			
			<form  action="" method="post">	
			<tr>
				
				<td  width="80">
					添加货品
				</td>
				<?php foreach ($arr as $v){?>
					<?php if($v[0]['natype']==1){?>
                
					<td>
						<select name="glvalue[]" class="form-control">
							<option value="">
								请选择
							</option>
							<?php foreach ($v as $b){?>
							<option value="<?php echo $b['sid']?>">
								<?php echo $b['shopvalue']?>
							</option>
							<?php }?>
						</select>
					</td>
					
               <?php }?>
				<?php }?>
				<td>
					<input id="exampleInputEmail1" class="form-control" type="text"name="gltotal">
				</td>
				<td>
					<input type="hidden" name="goods_gid" value="<?php echo $_GET['gid']?>"/>
					<input id="exampleInputEmail1" class="form-control" type="text"name="glnum">
				</td>
					
				
			</tr>
			<tr><td colspan="6"><input type="submit" value="添加货品" class="btn btn-success btn-block"/></td>
				
			</tr>
			</form>
		</table>
		
	</body>
</html>
